<?php

// Database connection variables

$dbServer = "acuario.ecci.ucr.ac.cr";

$dbDatabase = "bdusj2";

$dbUser = "us2";

$dbPass = "usj2";



$sConn = mysql_connect($dbServer, $dbUser, $dbPass)

or die("Couldn't connect to database server");



$dConn = mysql_select_db($dbDatabase, $sConn)

or die("Couldn't connect to database $dbDatabase");



$dbQuery = "SELECT idPlantilla, nombrePlantilla, tipoPlantilla ";

$dbQuery .= "FROM Plantillas ";

$dbQuery .= "ORDER BY nombrePlantilla ASC";

$result = mysql_query($dbQuery) or die("Couldn't get file list");

//We start of by connecting to our database and using a select query to get the id, title and type of each file in our database. Notice how I haven't used "SELECT *" in the select query? If I did, then MySQL would return the datosPlantilla field for each record as well, which would make our query extremely slow and inefficient because we don't actually need that field for our script.

?>


<a href="http://www.devarticles.com"><img border="0" src="http://www.devarticles.com/dlogo.gif"></a>

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">

<tr>

<td width="34%" bgcolor="#FF9900" height="21">

<p style="margin-left: 10"><b><font size="2" face="Verdana" color="#FFFFFF">

Description</font></b></td>

<td width="33%" bgcolor="#FF9900" height="21">

<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">

Type</font></b></td>

<td width="33%" bgcolor="#FF9900" height="21">

<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">

File</font></b></td>

</tr> 

<?php

//As mentioned above, we will be displaying each file as a table row. The HTML code above creates this table.

while($row = mysql_fetch_array($result))

{

?>

<tr>

<td width="34%" bgcolor="#FFDCA8" height="21">

<p style="margin-left: 10; margin-right: 10">

<font face="Verdana" size="1">

<?php echo $row["nombrePlantilla"]; ?>

</font>

</td>



<td width="33%" bgcolor="#FFDCA8" height="21">

<p style="margin-left: 10">

<font face="Verdana" size="1">

<?php echo $row["tipoPlantilla"]; ?>

</font>

</td>



<td width="33%" bgcolor="#FFDCA8" height="21">

<p style="margin-left: 10"><font face="Verdana" size="1">

<a href="Descargar_archivo.php?fileId=<?php echo $row["idPlantilla"]; ?>">

Download now

</a></font>

</td>

</tr>



<?php

}

echo "</table>";

?>



<html>

<head>

<title> Upload a File </title>

</head>


<body bgcolor="#FFFFFF">

<form enctype="multipart/form-data" name="frmUploadFile" action="Subir_archivo.php" method="POST">


<a href="http://www.devarticles.com">

<img border="0" src="http://www.devarticles.com/dlogo.gif">

</a>

<table border="0" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">

<tr>

<td width="100%" bgcolor="#FF9900" height="22" colspan="2">

<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">

Upload a File</font></b></td>

</tr>

<tr>

<td width="100%" bgcolor="#FFE3BB" colspan="2">

<p style="margin-left: 10; margin-right: 10"><font face="Verdana" size="2">

<br>Please select a file from your local computer to upload to our web server 

for saving in our database. This file can be of any type you like. Once you 

have chosen a file, please click on the &quot;Upload this file&quot; button below.&nbsp;

&nbsp;<br>&nbsp;</font></td>

</tr>

<tr>

<td width="15%" bgcolor="#FFE3BB">

<p style="margin-left: 10"><font face="Verdana" size="2">

File Description:</font></td>

<td width="85%" bgcolor="#FFE3BB">

<input type="text" name="strDesc" size="20" maxlength="50"></td>

</tr>

<tr>

<td width="15%" bgcolor="#FFE3BB">

<p style="margin-left: 10"><font face="Verdana" size="2">File Location:</font></td>

<td width="85%" bgcolor="#FFE3BB">

<font face="Verdana" size="2">

<input type="file" name="file" id="file" size="20"></font></td>


</tr>

<tr>

<td width="33%" bgcolor="#FFE3BB">

<p style="margin-left: 10"><font face="Verdana" size="2">

<br>

<br>

&nbsp;</font></td>

<td width="67%" bgcolor="#FFE3BB">

<font face="Verdana" size="2">

<input type="submit" value="Upload this file" name="cmdSubmit"></font></td>

</tr>

</table>

</form>

</body>

</html>
